/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: ufro ufro
 * License Type: Evaluation
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class PersonaDAOImpl implements orm.dao.PersonaDAO {
	private static final org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(PersonaDAOImpl.class);
	public Persona loadPersonaByORMID(int id) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return loadPersonaByORMID(session, id);
		}
		catch (Exception e) {
			_logger.error("loadPersonaByORMID(int id)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona getPersonaByORMID(int id) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return getPersonaByORMID(session, id);
		}
		catch (Exception e) {
			_logger.error("getPersonaByORMID(int id)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByORMID(int id, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return loadPersonaByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadPersonaByORMID(int id, org.hibernate.LockMode lockMode)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona getPersonaByORMID(int id, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return getPersonaByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			_logger.error("getPersonaByORMID(int id, org.hibernate.LockMode lockMode)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByORMID(PersistentSession session, int id) {
		try {
			return (Persona) session.load(orm.Persona.class, new Integer(id));
		}
		catch (Exception e) {
			_logger.error("loadPersonaByORMID(PersistentSession session, int id)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona getPersonaByORMID(PersistentSession session, int id) {
		try {
			return (Persona) session.get(orm.Persona.class, new Integer(id));
		}
		catch (Exception e) {
			_logger.error("getPersonaByORMID(PersistentSession session, int id)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) {
		try {
			return (Persona) session.load(orm.Persona.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			_logger.error("loadPersonaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona getPersonaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) {
		try {
			return (Persona) session.get(orm.Persona.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			_logger.error("getPersonaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona[] listPersonaByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return listPersonaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("listPersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona[] listPersonaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return listPersonaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("listPersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona[] listPersonaByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From orm.Persona as Persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Persona[]) list.toArray(new Persona[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listPersonaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona[] listPersonaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From orm.Persona as Persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Persona[]) list.toArray(new Persona[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listPersonaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return loadPersonaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("loadPersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return loadPersonaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadPersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByQuery(PersistentSession session, String condition, String orderBy) {
		Persona[] personas = listPersonaByQuery(session, condition, orderBy);
		if (personas != null && personas.length > 0)
			return personas[0];
		else
			return null;
	}
	
	public Persona loadPersonaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		Persona[] personas = listPersonaByQuery(session, condition, orderBy, lockMode);
		if (personas != null && personas.length > 0)
			return personas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePersonaByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return iteratePersonaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("iteratePersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public static java.util.Iterator iteratePersonaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession();
			return iteratePersonaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("iteratePersonaByQuery(String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public static java.util.Iterator iteratePersonaByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From orm.Persona as Persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iteratePersonaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public static java.util.Iterator iteratePersonaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From orm.Persona as Persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iteratePersonaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona createPersona() {
		return new orm.Persona();
	}
	
	public boolean save(orm.Persona persona) {
		try {
			orm.VOSOAPproyectodesarrolloPersistentManager.instance().saveObject(persona);
			return true;
		}
		catch (Exception e) {
			_logger.error("save(orm.Persona persona)", e);
			throw new RuntimeException(e);
		}
	}
	
	public boolean delete(orm.Persona persona) {
		try {
			orm.VOSOAPproyectodesarrolloPersistentManager.instance().deleteObject(persona);
			return true;
		}
		catch (Exception e) {
			_logger.error("delete(orm.Persona persona)", e);
			throw new RuntimeException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Persona persona) {
		try {
			if(persona.getCiudades() != null) {
				persona.getCiudades().getPersona().remove(persona);
			}
			
			return delete(persona);
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new RuntimeException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Persona persona, org.orm.PersistentSession session) {
		try {
			if(persona.getCiudades() != null) {
				persona.getCiudades().getPersona().remove(persona);
			}
			
			try {
				session.delete(persona);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new RuntimeException(e);
		}
	}
	
	public boolean refresh(orm.Persona persona) {
		try {
			orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession().refresh(persona);
			return true;
		}
		catch (Exception e) {
			_logger.error("refresh(orm.Persona persona)", e);
			throw new RuntimeException(e);
		}
	}
	
	public boolean evict(orm.Persona persona) {
		try {
			orm.VOSOAPproyectodesarrolloPersistentManager.instance().getSession().evict(persona);
			return true;
		}
		catch (Exception e) {
			_logger.error("evict(orm.Persona persona)", e);
			throw new RuntimeException(e);
		}
	}
	
	public Persona loadPersonaByCriteria(PersonaCriteria personaCriteria) {
		Persona[] personas = listPersonaByCriteria(personaCriteria);
		if(personas == null || personas.length == 0) {
			return null;
		}
		return personas[0];
	}
	
	public Persona[] listPersonaByCriteria(PersonaCriteria personaCriteria) {
		return personaCriteria.listPersona();
	}
}
